<?
include('../seguridad.php');
include('../bd.php');
Conectar();
if($_POST[borrar]!='yes'){
	if(!$_POST[stock]){$_POST[stock]='no';}
	if(!$_POST[online]){$_POST[online]='no';}else if($_POST[stock]=='no'){$_POST[online]='no';}
	if(!$_POST[promotions]){$_POST[promotions]='no';}
	$_price=$_POST[price_d].$_POST[price_c];
$sql = "UPDATE products SET price='".$_price."', stock='".$_POST[stock]."', online='".$_POST[online]."', promotions='".$_POST[promotions]."' WHERE id='".$_POST[id]."'";
mysql_query($sql) or die(mysql_error());
}else if($_POST[borrar]=="yes"){
// borro imagenes
	for ($i = 1; $i < 4; $i++) {
		if(file_exists('../../img_products/'.$_POST[code].'-'.$i.'.jpg')){
		unlink('../../img_products/'.$_POST[code].'-'.$i.'.jpg');}
		if(file_exists('../../img_products/'.$_POST[code].'-'.$i.'_c.jpg')){
		unlink('../../img_products/'.$_POST[code].'-'.$i.'_c.jpg');}
		if(file_exists('../../img_overview/'.$_POST[code].'.jpg')){
		unlink('../../img_overview/'.$_POST[code].'_c.jpg');}
		if(file_exists('../../img_details/'.$_POST[code].'.jpg')){
		unlink('../../img_details/'.$_POST[code].'_c.jpg');}
		if(file_exists('../../img_installation/'.$_POST[code].'.jpg')){
		unlink('../../img_installation/'.$_POST[code].'_c.jpg');}
		if(file_exists('../../img_warranty/'.$_POST[code].'.jpg')){
		unlink('../../img_warranty/'.$_POST[code].'_c.jpg');}
	}

$sql = "DELETE FROM products WHERE id='".$_POST[id]."'";
mysql_query($sql) or die(mysql_error());
}
Desconectar();
header('Location: ../products.php');
?>